package com.sjz.myfrist;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

/***
 * ListView基本用法
 */
public class Csdn7  extends AppCompatActivity {

    private String[] data = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","A","B","C","D","E","F","G","H","I","J","K","L","M","N","A","B","C","D","E","F","G","H","I","J","K","L","M","N"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.csdn7);
        //首先准备好一个数据数组用来展示，通过适配器将数据传给ListView，ArrayAdapter的构造函数中依次传入上下文、ListView子项布局的id，要适配的数据
        // 注意：这里使用的android.R.layout.simple_list_item_1为Android内置的布局文件，里面只有一个TextView，用于简单显示一段文本。
        // //最后调用ListView的setAdapter()方法，将适配器对象传进去，这样ListView和数据之间的关联就建立完成。
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(Csdn7.this, android.R.layout.simple_list_item_1, data);
        ListView listView = findViewById(R.id.list_view);
        listView.setAdapter(adapter);
    }
}
